﻿using NLog;
using NLog.Config;
using NLog.Targets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WmsToVna.Util
{
    public class NlogConfig
    {
        public static void Config()
        {
            // Step 1. Create configuration object 
            var config = new LoggingConfiguration();

            var fileTarget1 = new FileTarget();
            config.AddTarget("file", fileTarget1);
            fileTarget1.FileName = "${basedir}/Logs/${shortdate}/${shortdate}.txt";
            fileTarget1.Layout = "${longdate}|${event-properties:item=EventId_Id:whenEmpty=0}|${uppercase:${level}}|${logger}|${message} ${onexception:${exception:format=message} ${newline} ${stacktrace} ${newline}";
            fileTarget1.ArchiveFileName = "${basedir}/Logs/${shortdate}/${shortdate}-{#####}.txt";
            fileTarget1.ArchiveAboveSize = 1024000;
            fileTarget1.ArchiveNumbering = ArchiveNumberingMode.Sequence;

            var fileTarget2 = new FileTarget();
            config.AddTarget("file", fileTarget2);
            fileTarget2.FileName = "${basedir}/Logs/${shortdate}/${shortdate}-submit.txt";
            fileTarget2.Layout = "${longdate}|${event-properties:item=EventId_Id:whenEmpty=0}|${uppercase:${level}}|${logger}|${callsite}:${callsite-linenumber}|${message} ${onexception:${exception:format=message} ${newline} ${stacktrace} ${newline}";
            fileTarget2.ArchiveFileName = "${basedir}/Logs/${shortdate}/${shortdate}-submit-{#####}.txt";
            fileTarget2.ArchiveAboveSize = 1024000;//字节
            fileTarget2.ArchiveNumbering = ArchiveNumberingMode.Sequence;

      
            

            config.LoggingRules.Add(new LoggingRule(NlogLogger.Log.ToString(), LogLevel.Debug, fileTarget1));

        


            LogManager.Configuration = config;


            NLog.LogManager.GetLogger(NlogLogger.Log.ToString()).Debug("Hello,Nlog~~~~");
           
        }
       public enum NlogLogger
        {
            Log,

        }
    }

}
